package com.toocms.jinjuhang.ui.index

import android.os.Bundle
import androidx.databinding.ObservableField
import androidx.databinding.ObservableFloat
import com.blankj.utilcode.util.ConvertUtils
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.data.goods.CommodityItemData
import com.toocms.jinjuhang.ui.commodity.detils.CommodityDetailsFgt
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.base.MultiItemViewModel
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class IndexRecommendCommodityItemModel(
    viewModel: BaseViewModel<*>,
    val item: ObservableField<CommodityItemData>,
    recommendCommodityPosition: Int
) :
    MultiItemViewModel<BaseViewModel<*>>(viewModel) {

    val paddingStartObservableFloat = ObservableFloat(0f)
    val paddingTopObservableFloat = ObservableFloat(0f)
    val paddingEndObservableFloat = ObservableFloat(0f)
    val paddingBottomObservableFloat = ObservableFloat(0f)

    val itemClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        item.get()?.apply {
            val bundle = Bundle()
            bundle.putString(Constants.BundleKey.KEY_GOODS_ID, goods_id)
            viewModel.startFragment(CommodityDetailsFgt::class.java, bundle)
        }
    })

    init {
        itemType = Constants.RecyclerViewItemType.ITEM_TYPE_TEN
        when (recommendCommodityPosition % 4) {
            0 -> {
                paddingStartObservableFloat.set(ConvertUtils.dp2px(15f).toFloat())
                paddingEndObservableFloat.set(ConvertUtils.dp2px(0f).toFloat())
            }
            1 -> {
                paddingStartObservableFloat.set(ConvertUtils.dp2px(10f).toFloat())
                paddingEndObservableFloat.set(ConvertUtils.dp2px(5f).toFloat())
            }
            2 -> {
                paddingStartObservableFloat.set(ConvertUtils.dp2px(5f).toFloat())
                paddingEndObservableFloat.set(ConvertUtils.dp2px(10f).toFloat())
            }
            3 -> {
                paddingStartObservableFloat.set(ConvertUtils.dp2px(0f).toFloat())
                paddingEndObservableFloat.set(ConvertUtils.dp2px(15f).toFloat())
            }
        }
        if (3 < recommendCommodityPosition) {
            paddingTopObservableFloat.set(ConvertUtils.dp2px(10f).toFloat())
        }
    }
}